Skip to content

Throw directly instead of replacing error handler in ext/date #6954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2021

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented May 6, 2021

Those branches and/or functions are only called from the OOP/constructor API as such there is no need to use zend_replace_error_handling().

One usage of this remains in the timezone_initialize() which could have a parameter added to signal if it should throw directly.

@Girgias Girgias force-pushed the date-throw-exception-directly branch from 63b440f to 7988eaf Compare May 6, 2021 20:34
if ((flags & PHP_DATE_INIT_CTOR) && err && err->error_count) {
/* spit out the first library error message, at least */
php_error_docref(NULL, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", time_str,
zend_throw_error(zend_ce_exception, "Failed to parse time string (%s) at position %d (%c): %s", time_str,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be zend_throw_exception_ex, same for the others.

@@ -4109,19 +4102,17 @@ PHP_FUNCTION(date_interval_format)
}
/* }}} */

static int date_period_initialize(timelib_time **st, timelib_time **et, timelib_rel_time **d, zend_long *recurrences, /*const*/ char *format, size_t format_length) /* {{{ */
static void date_period_initialize(timelib_time **st, timelib_time **et, timelib_rel_time **d, zend_long *recurrences, /*const*/ char *format, size_t format_length) /* {{{ */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would have been nicer to retain the return value and check that instead of EG(exception).

@Girgias Girgias force-pushed the date-throw-exception-directly branch from 7988eaf to dc6703c Compare May 7, 2021 10:02
if ((flags & PHP_DATE_INIT_CTOR) && err && err->error_count) {
/* spit out the first library error message, at least */
php_error_docref(NULL, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", time_str,
zend_throw_exception_ex(NULL, 0, "Failed to parse time string (%s) at position %d (%c): %s", time_str,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I keep E_WARNING as the Exception code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't use exception codes.

@Girgias Girgias merged commit 2f1d0f2 into php:master May 7, 2021
@Girgias Girgias deleted the date-throw-exception-directly branch May 7, 2021 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants